import { asyncRoutes, constantRoutes } from '@/router'

const state = {
  routes: constantRoutes.concat(asyncRoutes),
  addRoutes: asyncRoutes,
  initialized: false
}

const mutations = {
  SET_ROUTES: (state, routes) => {
    state.addRoutes = routes
    state.routes = constantRoutes.concat(routes)
  },
  SET_INITIALIZED: (state, status) => {
    state.initialized = status
  }
}

const actions = {
  generateRoutes({ commit }) {
    return new Promise(resolve => {
      commit('SET_INITIALIZED', true)
      resolve(asyncRoutes)
    })
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
